package cn.duli.myvideo.controller;

import cn.duli.myvideo.pojo.VarietyComment;
import cn.duli.myvideo.service.VarietyCOmmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/varietyComment")
public class VarietyCommentController {

    @Resource
    private VarietyCOmmentService varietyCOmmentService;


    /**
     * 分页查找所有的综艺评论数
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/findAll")
    public PageInfo<VarietyComment> findAll(
        @RequestParam(defaultValue = "1") int pageNo,
        @RequestParam(defaultValue = "2") int pageSize) {
    PageHelper.startPage(pageNo,pageSize);
    PageInfo<VarietyComment> pageInfo = new PageInfo<>(varietyCOmmentService.findAll());
        return pageInfo;
    }


    /**
     * 根据用户id查找当前的综艺评论数
     * @param uId
     * @return
     */
    @GetMapping("/findByUserId/{uId}")
    public List<VarietyComment> findByUserId(@PathVariable("uId") Integer uId){
        return varietyCOmmentService.findByUserId(uId);
    }


    /**
     * 根据综艺id查找当前的综艺评论数
     * @param vId
     * @return
     */
    @GetMapping("/findByVarietyId/{vId}")
    public List<VarietyComment> findByVarietyId(@PathVariable("vId") Integer vId){
        return varietyCOmmentService.findByVarietyId(vId);
    }

    /**
     * 新增综艺评论
     * @param varietyComment
     */
    @PostMapping("/save")
    public void save(@RequestBody VarietyComment varietyComment){
        varietyCOmmentService.save(varietyComment);
    }


    /**
     * 根据综艺评论id删除此条评论
     * @param vcId
     */
    @RequestMapping("/deleteById/{vcId}")
    public void deleteById(@PathVariable("vcId") Integer vcId){
        varietyCOmmentService.deleteById(vcId);
    }
}
